package com.swt.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swt.domain.Goods;
import com.swt.service.GoodsService;
import com.swt.domain.Goods;
import com.swt.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 苏
* @description 针对表【okayapi_goods(商品表)】的数据库操作Service实现
* @createDate 2022-05-16 09:40:37
*/
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public List<Goods> selectAllGoods() {
        return goodsMapper.selectList(null) ;
    }

    @Override
    public int delectGoods(String id) {
        return goodsMapper.deleteById(id);
    }

    @Override
    public int updateGoods(Goods goods) {
        return goodsMapper.updateById(goods);
    }

    @Override
    public int inserGoods(Goods goods) {
        return goodsMapper.insert(goods);
    }

    @Override
    public Goods selectbyGoodid(String id) {
        return goodsMapper.selectById(id);
    }

    @Override
    public Page<Goods> pageGoods(Integer page, Integer start,Goods goods) {
        Page<Goods> userPge = new Page<>(page,start);
        LambdaQueryWrapper<Goods> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(Goods::getCreateTime);
        if (goods != null ){
            lqw.like(StringUtils.isNotEmpty(goods.getGoodsName()),Goods::getGoodsName,goods.getGoodsName());

            }
        return goodsMapper.selectPage(userPge,lqw);
    }
}




